/**
 * Created by Administrator on 2017/5/12.
 */

/*判断图片加载完了从而设置高度*/
var img = new Image();
img.src="../../images/shiyu/appointment02.png";
function imgLoad(img, callback) {
    var timer = setInterval(function() {
        if(img.complete) {
            callback(img)
            clearInterval(timer)
        }
    }, 50)
}
imgLoad(img,function() {
    $(".swiper-container").css("height","23vh");
    mySwiper.slideTo(2, 1, false);
    $(".star").eq(2).show();
})

//初始化轮播
    //mySwiper.activeIndex是当前显示的第几个(从0开始)
var mySwiper = new Swiper(".swiper-container", {
    slidesPerView: "auto",
    centeredSlides: !0,
    watchSlidesProgress: !0,
    pagination: ".swiper-pagination",
    paginationClickable: true,
    slidesPerView : 'auto',
    onTransitionEnd: function(swiper){
        $(".star").hide();
        $(".star").eq(swiper.activeIndex).show();
        swpierCallback(swiper.activeIndex);
    },
    onProgress: function(a) {
        var b, c, d;
        for (b = 0; b < a.slides.length; b++) {
            c = a.slides[b], d = c.progress, scale = 1 - Math.min(Math.abs(.2 * d), 1), es = c.style, es.opacity = 1 - Math.min(Math.abs(d / 3), 1), es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = func(d);
        }

    },
    onSetTransition: function(a, b) {
        for (var c = 0; c < a.slides.length; c++) es = a.slides[c].style, es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = b + "ms"
    }
});
//设置轮播参数
function func(d){
    if(d==0||Math.abs(d)<0.1){
        return "translate3d(0px,0px," + -Math.abs(150 * d) + "px) scale(1.2)";
    }else if(Math.abs(d)<1.1){
        return "translate3d(0px,24px," + -Math.abs(150 * d) + "px) scale(1.1)";
    }else {
        return "translate3d(0px,48px," + -Math.abs(150 * d) + "px) ";
    }
}
//切换美容师完成后   所执行的函数
function swpierCallback(index) {
    //index是切换到第几个的索引等同于mySwiper.activeIndex
}

//其他
//初始化日期

var day=new  Date();
var dayHours=day.getHours();
var dayMinutes=day.getMinutes();
var allDayTime=$("tr td span");
init();
function init() {
    allDayTime.each(function (i,element) {
        var tempElement=$(element);
        var tempArr=element.innerHTML.split(":");
        if(tempArr[0]-0<dayHours){
            if(!tempElement.hasClass("colorGray")){
                tempElement.addClass("colorGray");
            }
        }else if(tempArr[0]-0==dayHours){
            if(dayMinutes>tempArr[1]){
                if(!tempElement.hasClass("colorGray")){
                    tempElement.addClass("colorGray");
                }
            }
        }
    })
}
var dateWeek=(new  Date().getDay()+3)%7;
if(!dateWeek){
    dateWeek=7;
}
var dateDay=["一","二","三","四","五","六","日"];
$(".four").text("周"+dateDay[dateWeek-1]);
$(".five").text("周"+dateDay[dateWeek%7]);
$(".six").text("周"+dateDay[(dateWeek+1)%7]);
$(".seven").text("周"+dateDay[(dateWeek+2)%7]);
$(".editData").click(function () {
    console.log("当前是第"+(mySwiper.activeIndex+1)+"个美导");
})
//table点击选择预约时间
$(".table table tr td span").click(function (e) {
    var clickTarget=$(e.target);
    if(clickTarget.hasClass("colorRed")){
        $(".table table tr td span").removeClass("colorRed");
        //当前时间已经有预约的情况
    }else if(!clickTarget.hasClass("colorGray")){
        $(".table table tr td span").removeClass("colorRed");
        clickTarget.addClass("colorRed");
        //当前时间没有预约的情况    并且     当前时间为可选状态
    }else {
        //当前时间没有预约的情况    并且     当前时间为不可选状态
       // $(".table table tr td span").removeClass("colorRed");
    }
})
//切换天
$(".table table tr th").click(function (e) {
    var selectDay=$(e.target);

    if(!selectDay.hasClass("today")){
        $(".table table tr th").removeClass("today");
        selectDay.addClass("today");

        $(".table table tr td span").removeClass("colorRed").removeClass("colorGray");

    }
    if($(this).index()==0){
        init();
    }
})
//预约
function yuyue() {
    $(".tip").css("display","");
}
$(".commitAppointment").click(function () {
    $(".tip").css("display","");
})
$(".weui-mask").click(function () {
    $(".tip").css("display","none");
})

$(".weui-tabbar__item").click(function (e) {
    $(".weui-tabbar__item p").css("color","#999");
    if(e.target.nodeName.toLocaleLowerCase() === 'a'){
        $(e.target).find("p").css("color","#f76492");
    }else {
        $(e.target).parent().find("p").css("color","#f76492");
    }
})

var zhuangtai=true;
var tempTimer;
var newTimer;
var showTip=function (str,type,time) {
    if(!time){ time=3000;  }
    tempTimer=newTimer;
    newTimer=setTimeout(function () {  $(".msg").css("display","none");  zhuangtai=true;  },time)
    if(!zhuangtai){        clearTimeout(tempTimer);    }
    zhuangtai=false;
    $(".weui-toast__content").text(str);
    if(type==2){
        $(".msg .weui-icon_toast").removeClass("weui-icon-success-no-circle").addClass("weui-icon-cancel");
        $('head').append("<style>.msg .weui-icon-cancel:before{ font-size: 43px; color: #999; }.msg .weui-icon-cancel{ margin-bottom:1rem;}</style>");
        $(".msg .weui-icon-cancel").click(function () {
            $(".msg").css("display","none");
            clearTimeout(newTimer);
            zhuangtai=true;
        });
    }else {
        $(".msg .weui-icon_toast").removeClass("weui-icon-cancel").addClass("weui-icon-success-no-circle");
    }
    $(".msg").css({"display":""});
}
//获取验证码
var waitTime=60;
var waitStatus=false;
var regPhoneNum = /^((1[3,5,7,8]{1})+\d{9})$/;
$(".obtain").click(function () {
    if(waitStatus){
        return;
    }
    var phoneNumber=$(".phoneNumber");
    if(phoneNumber.val()==null||phoneNumber.val()==""){
        showTip("请输入手机号",2);
        return;
    }
    if(!regPhoneNum.test(phoneNumber.val())){

    }
    waitStatus=true;
    var obtain=$(".obtain .weui-vcode-btn");
    waitTime--;
    obtain.text(waitTime+"秒");

    //假定此时发送成功
    var timer1=setTimeout(function () {
        showTip("短信已发送");
    },1000)
    var timer=setInterval(function () {
        waitTime--;
        obtain.text(waitTime+"秒");
        if(waitTime<1){
            clearInterval(timer);
            waitTime=60;
            waitStatus=false;
            obtain.text("获取");
        }
    },1000)

})
$(".weui-cell__bd").click(function () {
    $(this).parent().remove();
})